package com.example.asus.a522;

import android.content.Intent;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class FirstActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Log.d("FirstActivity",this.toString());

        setContentView(R.layout.first_layout);
        Button btn1 = (Button)findViewById(R.id.button_1);
        btn1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //Intent intent = new Intent("com.example.asus.a522.ACTION_START");
                //intent.addCategory("com.example.asus.a522.MY_CATEGORY");
                //startActivity(intent);
                //Intent intent = new Intent(Intent.ACTION_VIEW);
                //intent.setData(Uri.parse("http://www.baidu.com"));
                //Intent intent = new Intent(Intent.ACTION_DIAL);
                //intent.setData(Uri.parse("tel:13434120620"));
                //String data = "Hello SecondActivity";
                //Intent intent = new Intent(FirstActivity.this,SeccondActivity.class);
                //intent.putExtra("extra_data",data);
                Intent intent = new Intent(FirstActivity.this,SeccondActivity.class);
                //startActivityForResult(intent,1);
                startActivity(intent);
            }
        });
    }
    @Override
    protected void onActivityResult(int requestCode,int resultCode,Intent data)
    {
        switch (requestCode){
            case 1:
                if(resultCode==RESULT_OK){
                    String returnedData = data.getStringExtra("data_return");
                    Log.d("FirstActivity",returnedData);
                }
                break;
                default:
        }

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu,menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()){
            case R.id.add_item:
                Toast.makeText(this,"你点击了添加",Toast.LENGTH_SHORT).show();
                break;
            case R.id.remove_item:
                Toast.makeText(this,"你点击了删除",Toast.LENGTH_SHORT).show();
                break;
            case R.id.check_item:
                Toast.makeText(this,"你点击了查看",Toast.LENGTH_SHORT).show();
                break;
             default:
        }
        return true;
    }

    @Override
    protected  void onRestart()
    {
        super.onRestart();
        Log.d("FirstActivity","onRestart");
    }

}
